<?php 
$ubigeo = '';
$buscar = false;
$rowc = '';
$usrid = '';
$codcli = '';
$feccre = '';
$found = false;
include('../Connections/KRAPPERCON.php');
include ("../Connections/Accesos.php");

$callback = getVal('callback');
?>
<?php 
$return = '';
if (isset($_POST['return'])){
$return = getVal('return');
}

$codcli = trim(getGet('codcli'));

if ($codcli != ''){
$query = "call sp_getCliente('".$codcli."','','') ;";
$buscar = true;
$cnt = 0;
$res = $mysqli->query($query);
if ($res) {
		if($rowc = $res->fetch_array()) {
			$found = true;
			$usrid = $rowc['UserID'];
			$feccre = $rowc['ClientFecCre'];
			}
$res->close();
	
	$mysqli->check_result();
	
}
}			

?>
<div>
<input type="button"  name="btn_ncli" id="btn_ncli" onclick="nuevoCliente()" value="Nuevo">
<input type="button"  name="btn_gcli" id="btn_gcli" onclick="grabarCliente()" value="Grabar">
<input type="button"  name="btn_lcli" id="btn_lcli" onclick="listarCliente()" value="Listado">&nbsp;&nbsp;<input type="text" id="t_cli_ld" onkeypress="if(event.keyCode==13)loadClient()" /></div>
<?php 
if ($found){
?>
<div class="subTit">
<?php 
echo "Cliente ".$codcli." creado por ".$usrid." el ".$feccre;
?>
</div>
<?php
}
?>
<table width="100%" border="0" class="inputCss" id="tbl_dat_cli" cellpadding="0" cellspacing="0">
<tr>
<td><strong>C&oacute;digo</strong></td>
<td><input name="t_cod_cli" type="text" id="t_cod_cli" disabled="disabled" placeholder = '[Autogenerado]' /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Apellidos y Nombres o  Razon Social</td>
<td><input name="t_nom_cli" class="clsReq" type="text" id="t_nom_cli" size="70" maxlength="70"  /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
  <td>DNI/RUC</td>
  <td><input name="t_doc_cli" class="clsReq" type="text" id="t_doc_cli" size="20" maxlength="12" value="<?php echo getVal('prevCli'); ?>"  /></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>Tipo Cliente</td>
  <td><select name="cb_tip_cli" id="cb_tip_cli" 
>
      <?php

$query="select*from tt_clienttype;"; 
$res = $mysqli->query($query);
if ($res) {
while($row = $res->fetch_assoc()) {
?>
      <option value="<?php echo ( $row["CliTypeID"]) ?>" > <?php echo ($row["CliTypeTxt"]) ?></option>
      <?php
}
$res->close();
	$mysqli->check_result();
}
?>
  </select></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
<td>Direccion</td>
<td><input name="t_dir_cli" class="clsReq" type="text" id="t_dir_cli" size="50" maxlength="80"  /></td>
<td>Telefono</td>
<td><input name="t_tlf_cli" type="text" id="t_tlf_cli" size="15"  /></td>
</tr>
<tr>
<td>Direccion 2</td>
<td><input name="t_dir2_cli" type="text" id="t_dir2_cli" size="50" maxlength="60"  /></td>
<td>Celular</td>
<td><input name="t_cel_cli" type="text" id="t_cel_cli" size="15" maxlength="12"  /></td>
</tr>
<tr>
<td>Contacto</td>
<td><input name="t_con_cli" type="text" id="t_con_cli" size="30" maxlength="30"  /></td>
<td>Correo</td>
<td><input name="t_cor_cli" type="text" id="t_cor_cli" size="30" maxlength="50"  /></td>
</tr>
<tr>
  <td>Zona</td>
  <td><select name="cb_zon_cli" id="cb_zon_cli" >
      <?php

$query="select * from tt_clientzone;"; 
$res = $mysqli->query($query);
if ($res) {
while($row = $res->fetch_assoc()) {
?>
      <option value="<?php echo ( $row["CliZoneID"]) ?>" > <?php echo ($row["CliZoneTxt"]) ?></option>
      <?php
}
$res->close();
$mysqli->check_result();
}


?>
  </select></td>
  <td>Estado</td>
  <td><select name="cb_est_cli" id="cb_est_cli">
      <option value="1" selected="selected">ACTIVO</option>
      <option value="0">INACTIVO</option>
  </select></td>
</tr>
<tr>
<td>Pa&iacute;s </td>
<td>
  <select name="cb_cli_pe" id="cb_cli_pe">
  <?php 
  include ('../Query_Min/getPaises.php');
  ?>
  </select></td>
<td class="noView"> Ubigeo</td>
<td class="noView"><div id="d_ubiprv_cl">
<?php
//include('/UbiGeo/UbigeoDefault.php'); 
?>
</div></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td><input type="checkbox" name="chk_cli_ret" id="chk_cli_ret" />
Agente de Retenci&oacute;n</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td><input type="checkbox" name="chk_cli_ret2" id="chk_cli_ret2" />
Agente de Percepci&oacute;n</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr class="noView">
  <td>Apellido Paterno</td>
  <td><input name="t_apep_cli" class="" type="text" id="t_apep_cli" size="30" maxlength="30"  /></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr class="noView">
  <td>Apellido Materno</td>
  <td><input name="t_apem_cli" type="text" id="t_apem_cli" size="30" maxlength="30"  /></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
<?php  if (isset($_POST['tip'])&& $_POST['tip']!=""){ 
?>
$('#t_cod').attr('disabled','disabled');


<?php 
}

?>

function nuevoCliente(){
//$('#d_ubiprv_cl').loadx('Mantenimientos/Ubigeo/UbigeoDefault.php',{ubigeo : '150101'});
$('#tbl_dat_cli input').removeAttr('disabled').val('');
$('#t_cod_cli').attr('disabled','disabled');
//$('#d_ubiprv').load('Mantenimientos/UbiGeo/Ubigeo.php',{ubigeo : '150101'});
<?php
echo "GEBI('cb_tip').value ='1'         ," ;
echo "GEBI('cb_est').value ='1'     ," ;
echo "GEBI('cb_zona').value ='1' ;   " ;?>
<?php  echo $tip ="" ?>


}
function grabarCliente(){

if (!$("#tbl_dat_cli").checkInput()){
	return;
}

var tip = "<?php  if (isset($_POST['tip'])){
echo $tip= $_POST['tip'];
}else{
echo $tip= "";
 }?>" ;
 
sendData('Mantenimientos/Opers/OpeCli.php',{
		oper : 'save',
		codcli : GEBI('t_cod_cli').value ,
		nombrecli : GEBI('t_nom_cli').value ,
		apepatcli : GEBI('t_apep_cli').value ,
		apematcli : GEBI('t_apem_cli').value ,
		direccioncli :  GEBI('t_dir_cli').value,
		est : GEBI('cb_est_cli').value ,
		docucli : GEBI('t_doc_cli').value ,
		cb_ubigeo : GEBI('cb_ubigeo').value,
		direccion2cli : GEBI('t_dir2_cli').value ,
		celularcli : GEBI('t_cel_cli').value,
		tlfcli : GEBI('t_tlf_cli').value ,
		correocli : GEBI('t_cor_cli').value,
		contactocli : GEBI('t_con_cli').value ,
		tipocli : GEBI('cb_tip_cli').value ,
		zona : GEBI('cb_zon_cli').value,
		ClientSort1 : '',
		tipo :  tip ,
		finder : '<?php echo $return;?>', 
		pais : GEBI('cb_cli_pe').value,
		reg1 : (GEBI('chk_cli_ret').checked?'1':'0'),
		callback : '<?php echo $callback;?>'
});	

}





function listarCliente(){
loadPage('Mantenimientos/Listas/LstCli.php',{ cli : GEBI('t_cod').value});

}

<?php 
if ($found) {
		?>
			GEBI('t_cod_cli').value ='<?php echo $rowc['ClientID']  ?>'   ;			
			GEBI('t_nom_cli').value ='<?php echo $rowc['ClientNom']  ?>'   ;  				   
			GEBI('t_apep_cli').value ='<?php echo $rowc['ClientApePat']  ?>'   ;     				     
			GEBI('t_apem_cli').value ='<?php echo $rowc['ClientApeMat']  ?>'   ; 					       
			GEBI('t_dir_cli').value ='<?php echo $rowc['ClientDirec']  ?>'   ;			   
			GEBI('cb_est_cli').value ='<?php echo $rowc['ClientSts']  ?>'   ;				  
			GEBI('t_doc_cli').value ='<?php echo $rowc['ClientNIF']  ?>'   ;					 
			GEBI('t_dir2_cli').value ='<?php echo $rowc['ClientDirec2']  ?>'   ;					 
			GEBI('t_cel_cli').value ='<?php echo $rowc['ClientCel']  ?>'   ;					  
			GEBI('t_tlf_cli').value ='<?php echo $rowc['ClientTelf']  ?>'   ;						
			GEBI('t_cor_cli').value ='<?php echo $rowc['ClientMail']  ?>'   ;							  
			GEBI('t_con_cli').value ='<?php echo $rowc['ClientContac']  ?>'   ;							  
			GEBI('cb_tip_cli').value ='<?php echo $rowc['CliTypeID']  ?>'   ;						  
			GEBI('cb_zon_cli').value ='<?php echo $rowc['CliZoneID']  ?>'   ;	
			GEBI('cb_cli_pe').value = '<?php echo $rowc['ClientPE']; ?>';
			GEBI('chk_cli_ret').checked = ('<?php echo $rowc['ClientReg1'];?>'==1?true:false);
			GEBI('chk_cli_per').checked = ('<?php echo $rowc['ClientReg2'];?>'==1?true:false);
			$('#d_ubiprv_cl').loadx('Mantenimientos/Ubigeo/Ubigeo.php',{ubigeo : '<?php echo $rowc['UbigeoID'] ?>'});
	<?php	
	}
elseif($buscar) {
?>
showError('El Codigo de Cliente no existe');
$('#d_ubiprv_cl').loadx('Mantenimientos/Ubigeo/UbigeoDefault.php',{ubigeo : '150101'});
<?php
}
elseif(!$buscar){
?>
$('#d_ubiprv_cl').loadx('Mantenimientos/Ubigeo/UbigeoDefault.php',{ubigeo : '150101'});
GEBI('cb_cli_pe').value = 'PE';
<?php 
}
?>

function loadClient(){
loadPage('Mantenimientos/MantCli.php',{ codcli : GEBI('t_cli_ld').value});
}

</script>
